<template>
  <a-card :bordered="false" class="withdrawal">
    <a-tabs default-active-key="10" @change="callback">
      <a-tab-pane :key="item" :tab="index" v-for="index,item in tabs"></a-tab-pane>
    </a-tabs>
    <section>
      <div class="theknightSearch table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="getList">
          <a-row :gutter="24">
            <a-col :md="5" :sm="5">
              <a-form-item label="订单号" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
                <a-input placeholder="请输入订单号" v-model="queryParam.orderNo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :md="11" :sm="11">
              <a-form-item label="支付时间" :labelCol="{span: 2}" :wrapperCol="{span: 18, offset: 1}">
                <section class="time-box">
                  <j-date v-model="queryParam.payTimeFrom" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss"
                    style="width:43%;min-width:0;" placeholder="开始时间"></j-date>
                  <span style="felx:1"> - </span>
                  <j-date v-model="queryParam.payTimeTo" :showTime="true" date-format="YYYY-MM-DD HH:mm:ss"
                    style="width:43%;min-width:0;" placeholder="结束时间"></j-date>
                </section>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="6">
              <a-button style="margin-left: 8px" @click="getList">搜索</a-button>
              <a-button style="margin-left: 8px" @click="withdrawal"
                v-if="queryParam.shopStatus==0||queryParam.siteStatus==0" v-has="'Take:withdrawal'">提现
              </a-button>
              <a-button style="margin-left: 8px" @click="onClose">刷新</a-button>
              <a-button style="margin-left: 8px" type="primary" icon="download" @click="handleExpor()">导出
              </a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <section class="table">
        <a-table ref="table" size="middle" bordered rowKey="id" :columns="columns" :pagination="ipagination"
          @change="changePage" :dataSource="List" :loading="loading"
          :rowSelection="{selectedRowKeys:selectedRowKeysArrey,onChange:onSelectChange}">
          <span slot="action" slot-scope="text, record">
            <a href="javaScript:;" v-if="record.updatablePCT" @click="editor(record)" v-has="'Take:top'">修改抽成</a>
          </span>
        </a-table>
      </section>
      <a-modal v-model="visible" title="修改抽成比例" @ok="handleOk">
        <a-form-item label="总部抽成比例" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
          <a-input v-model="infoData.systemPCT"></a-input>
        </a-form-item>
        <a-form-item label="分站抽成比例" :labelCol="{span: 6}" :wrapperCol="{span: 14, offset: 1}">
          <a-input v-model="infoData.sitePCT"></a-input>
        </a-form-item>
      </a-modal>
    </section>
  </a-card>

</template>
<script>
import {
  postAction,
  getAction
} from '@/api/manage'
import store from '@/store'
import { putAction } from '../../api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  mixins: [JeecgListMixin,],
  data() {
    return {
      visible: false,
      tabs: {},
      loading: false,
      queryParam: {
        pageNo: 1,
        pageSize: 10,
      },
      substationList: [],// 分站列表
      updStatus: {},
      List: [],
      infoList: [], //登录历史数据
      infoData: { systemPCT: '', sitePCT: '' },//选中数据
      selectedRowKeysArrey: [], //选中的id
      chooseOrder: '', // 选中的数据
      isBranchFlag: false,// 当前登录用户是否分站用户
      columns: [
        {
          title: '订单编号',
          align: "center",
          dataIndex: 'orderNo',
        },
        {
          title: '名称',
          align: "center",
          dataIndex: 'shopId_dictText',
        }, {
          title: '订单支付金额',
          align: "center",
          dataIndex: 'payAmount',
        },
        {
          title: '总部抽成比例',
          align: "center",
          dataIndex: 'systemPCT',
        },
        {
          title: '分站抽成比例',
          align: "center",
          dataIndex: 'sitePCT',
        },
        {
          title: '店铺抽成比例',
          align: "center",
          dataIndex: 'shopPCT',
        },
        {
          title: '总部抽成金额',
          align: "center",
          dataIndex: 'systemAmount',
        },
        {
          title: '分站抽成金额',
          align: "center",
          dataIndex: 'siteAmount',
        },
        {
          title: '店铺抽成金额',
          align: "center",
          dataIndex: 'shopAmount',
        },
        {
          title: '订单支付时间',
          align: "center",
          dataIndex: 'payTime',
        },
        {
          title: '修改时间',
          align: "center",
          dataIndex: 'updateTime',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      //标记页数；页码
      ipagination: {
        current: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        total: 0
      },
      url: {
        tbas: '/financeLine/status',
        list: '/financeLine/page',
        pct: '/financeLine/updatePCT',
        apply: '/financeGroup/apply',
        maxCount: '/financeGroup/maxCount',
        exportXlsUrl: '/financeLine/export',
      }
    }
  },
  created() {
    this.getTabs()
    if (store.getters.userInfo.userType == 1) {
      this.queryParam = { siteStatus: 0, pageNo: 1, pageSize: 10 }
    }
    if (store.getters.userInfo.userType == 2) {
      this.queryParam = { siteStatus: 0, pageNo: 1, pageSize: 10 }
    }
    if (store.getters.userInfo.userType == 3) {
      this.queryParam = { shopStatus: 0, pageNo: 1, pageSize: 10 }
    }
    this.getList()
    console.log("当前登录用户信息：", store.getters.userInfo.userType);//USER_INFO
  },
  methods: {
    handleExpor() {
      if (this.selectedRowKeysArrey.length != 0) {
        this.handleExportXls('结算订单')
      } else {
        this.$message.warning('未选择')
      }
    },
    withdrawal() {
      let that = this
      if (that.chooseOrder != '') {
        // this.chooseOrder.forEach(element => {
        getAction(that.url.maxCount).then(res => {
          console.log(res.result, "单次提现最大条数")
          if (res.code == 200) {
            if (that.selectedRowKeysArrey.length <= res.result) {
              postAction(that.url.apply, that.selectedRowKeysArrey).then(success => {
                if (success.code == 200) {
                  that.$message.success('成功')
                } else {
                  that.$message.warning(success.message)
                }
                that.onClose()
                console.log(success)
              })
            }
          }
        })
      }
    },
    handleOk() {
      console.log(this.infoData.sitePCT * 1 + this.infoData.systemPCT * 1)
      if (this.infoData.sitePCT * 1 + this.infoData.systemPCT * 1 <= 1) {
        putAction(this.url.pct, this.infoData).then(res => {
          if (res.code == 200) {
            this.visible = false
          } else {
            this.visible = false
          }
          this.getList()
          console.log(res)
        })
      } else {
        this.$message.warning("不能修改")
      }

    },
    editor(e) {
      this.infoData = e
      this.visible = true

    },
    // 查询分站
    getTabs() {
      getAction(this.url.tbas).then(res => {
        this.tabs = res.result
        console.log(this.tabs)
      })
    },
    callback(key) {
      if (store.getters.userInfo.userType == 1) {
        this.queryParam.siteStatus = key
      }
      if (store.getters.userInfo.userType == 2) {
        this.queryParam.siteStatus = key
      }
      if (store.getters.userInfo.userType == 3) {
        this.queryParam.shopStatus = key
      }
      this.queryParam.pageNo = 1
      this.ipagination.current = 1
      this.getList()
      this.queryParam.pageSize = 10;
      this.chooseOrder = ''
      this.selectedRowKeysArrey = []
    },
    getList() {
      this.loading = true
      postAction(this.url.list + '?pageNo=' + this.queryParam.pageNo + '&pageSize=' + this.queryParam.pageSize, this.queryParam).then(res => {
        console.log(res, "记录");
        if (res.success) {
          this.loading = false
        } else {
          this.loading = false
        }
        this.List = res.result.records
        this.ipagination.total = res.result.total;  // 页数
        this.ipagination.pageSize = res.result.size;  // 页数
      })
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      );
    },
    onClose() {
      this.selectedRowKeysArrey = []
      this.chooseOrder = ""
      this.queryParam.orderNo = ''
      this.queryParam.payTimeFrom = ''
      this.queryParam.payTimeTo = ''
      this.getList()

    },
    // 选中一行
    onSelectChange(a, b) {
      this.selectedRowKeysArrey = a;
      this.chooseOrder = b;
      console.log(this.selectedRowKeysArrey, "选中的数据");
      // this.infoData.sitePCT = this.chooseOrder
    },
    // 代理列表改变分页
    changePage(pagination) {
      this.ipagination.current = pagination.current
      console.log(pagination);
      this.queryParam.pageNo = pagination.current;
      this.queryParam.pageSize = pagination.pageSize;
      this.getList();
    }
  }
}
</script>
<style lang="less" scoped>
.withdrawal {
  .time {
    margin-top: 30px;
  }

  .theknightSearch {
    margin-top: -15px;
    padding: 15px 10px;

    .ant-form-item {
      width: 100%;
    }
  }

  .table-page-search-wrapper .ant-form-inline .ant-form-item {
    margin-bottom: 0px !important;
  }
}

.btn {
  button {
    margin-right: 10px;
  }
}
</style>